package java101;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class StateLettersFinal {


	public static void main(String[] args) throws IOException {
		String[] words = new String[50];
		
		char[] alphabet = new char[26];
		char letter = 'A';
		for (int h = 0; h < 26; h++, letter++) {
			alphabet[h] = letter;
		}
		
		int[] counter = new int[26];

			//Read in text file
			FileReader fileReader = new FileReader("50states.txt");
			
			//Turn file into readable code
			BufferedReader bufferedReader = new BufferedReader(fileReader); 

			
			//Allows the console to print one state per line
			for (int i=0; i<50; i++) {
				
			String oneLine = bufferedReader.readLine();
			oneLine = oneLine.toUpperCase();
			words[i] = oneLine;
			
			//Turn string into char
			
			for (int j = 0; j < words[i].length(); j++) {
				  char c = words[i].charAt(j);
			
			//If c matches alphabet letter, put it in appropriate array slot.
			
				  for (int k = 0; k < alphabet.length; k++) {
					  if (c == alphabet[k]) {
						  counter[k] = counter[k] + 1;
					  } //Closes if
				  } //Closes for "k"
			} //Closes for "j"
	} //Closes for "i"
			
			//Print slots with no content.
					
			for (int m = 0; m < 26; m++) {
				if (counter[m] == 0) {
					System.out.println("Minimum = " + counter[m] + " occurences with letter " + alphabet[m]);
				}
				}
			
//			Print the maximum
			
			int maximum = counter[0];

	        for (int p = 1; p < counter.length; p++)
	        {
	         if (counter[p] > maximum)
	         {
	        	 maximum = counter[p];
	          System.out.println("Maximum =  " + maximum + " occurences with letter " + alphabet[p]);
	         }
	        
	         
	         //This is in case the first letter occurs the most times.
	         
	         else {
	        	 System.out.println("Maximum =  " + maximum + " occurences with letter " + alphabet[0]); 
	        	 break;
	         }

	        }  
	}
	}


	

